﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Blackbird.Utilities
{
    /// <summary>
    /// Cache helper class.
    /// </summary>
    
    class ObjectCache<T, ID> where ID : ISerializable 
    {
        private Dictionary<ID,WeakReference> CachedObjects;

        int InstanceRegeneration = 0; //how many times has an object been regenerated?

        private Log log;

        public ObjectCache(int amount)
        {
            this.CachedObjects = new Dictionary<ID, WeakReference>(amount);
            this.log = new Log("ObjectCache");
        }

        public  T GetObject(ID id)
        {
            if (this.CachedObjects.ContainsKey(id))
            {
               //fetch somehow
                log.Debug("Retrieved object id : "+id);
                this.InstanceRegeneration++;
                return GetObject(id);
            }
            //object dead or not cached.
            return default(T); //hax
        }

       
    }
}
